/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Admin
 */
@Entity
@Table(name = "Program")
@NamedQueries({
    @NamedQuery(name = "Program.findAll", query = "SELECT s FROM Program s"),
    @NamedQuery(name = "Program.findByProgramId", query = "SELECT s FROM Program s WHERE s.id = :programId"),
    @NamedQuery(name = "Program.findByName", query = "SELECT s FROM Program s WHERE s.name = :name"),
    @NamedQuery(name = "Program.findByFaculty", query = "SELECT s FROM Program s WHERE s.faculty = :faculty")
})
public class Program implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ProgramId")
    private Long id;
    
    @JoinColumn(name = "FacultyId", referencedColumnName = "FacultyId")
    @ManyToOne(optional = true, cascade = CascadeType.PERSIST)
    private Faculty faculty;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "program")
    private List<Student> students;

    @Column(name = "Name")
    private String name;
    
    public Program(){
    }
    
    public Program(String name){
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    public void setId(Long id) {
        this.id = id;
    }

    public Faculty getFaculty() {
        return faculty;
    }

    public void setFaculty(Faculty faculty) {
        this.faculty = faculty;
    }

    public List<Student> getStudents() {
        return students;
    }

    public void setStudents(List<Student> students) {
        this.students = students;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Program)) {
            return false;
        }
        Program other = (Program) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return name + " (" + id + ")";
    }
    
}
